package com.zlzxm.shoesmarket.view.activity;

import android.content.Context;
import android.content.Intent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.fragment.FMRequestGoods;
import com.zlzxm.shoesmarket.view.widget.simpleead.SimpleHead;

import java.util.ArrayList;
import java.util.List;

/**
 * CREATE BY zlzxm ON 4/21/21
 * <br>
 *我的出求货
 */
public class ACMyRequestGood extends BaseActivity{


    public static void start(Context context) {
        Intent starter = new Intent(context, ACMyRequestGood.class);
        context.startActivity(starter);
    }

    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.ac_my_request_goods);
        SimpleHead simpleHead = ZViewHelp.findById(this,R.id.head);
        simpleHead.setTitle("我的出求货");
        simpleHead.setOnItemclicklistener(this::finish);
        TabLayout tabLayout = ZViewHelp.findById(this,R.id.tabLayout);
        tabLayout.addTab(tabLayout.newTab().setText("求货"));
        tabLayout.addTab(tabLayout.newTab().setText("出货"));

        ViewPager viewPager = ZViewHelp.findById(this,R.id.viewPager);
        viewPager.setAdapter(new MyPager(getSupportFragmentManager()));
        tabLayout.setupWithViewPager(viewPager);

    }

    @Override
    protected void initViewModule() {
        super.initViewModule();
    }

    @Override
    protected void initData() {
        super.initData();
    }


    class MyPager extends FragmentPagerAdapter{

        List<Fragment> list = new ArrayList<>();

        public MyPager(@NonNull FragmentManager fm) {
            super(fm,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
            list.add( FMRequestGoods.newInstance());
            list.add( FMRequestGoods.newInstance());
        }

        @NonNull
        @Override
        public Fragment getItem(int position) {
            return list.get(position);
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return position == 0 ?"求货":"出货";
        }
    }

}
